package com.zqj.project.common.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.Getter;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Description: SuperEntity
 * @Author: 22001010704 Zhang Qijian
 * @CreateTime: 2024/6/12 23:46
 * @Version: 1.0
 */
@Getter
public class SuperEntity<T> implements Serializable {

    public static final String FIELD_ID = "id";
    public static final String CREATE_TIME = "createTime";
    public static final String CREATE_TIME_COLUMN = "create_time";
    public static final String CREATED_BY = "createdBy";
    public static final String CREATED_BY_COLUMN = "created_by";
    @Serial
    private static final long serialVersionUID = -4603650115461757622L;
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    protected @NotNull(message = "id不能为空", groups = {Update.class}) T id;
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    protected LocalDateTime createTime;
    @TableField(value = "created_by", fill = FieldFill.INSERT)
    protected T createdBy;

    public SuperEntity() {
    }

    public SuperEntity(T id, LocalDateTime createTime, T createdBy) {
        this.id = id;
        this.createTime = createTime;
        this.createdBy = createdBy;
    }

    public SuperEntity<T> setId(T id) {
        this.id = id;
        return this;
    }

    public SuperEntity<T> setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
        return this;
    }

    public SuperEntity<T> setCreatedBy(T createdBy) {
        this.createdBy = createdBy;
        return this;
    }

    @Override
    public String toString() {
        return "SuperEntity(super=" + super.toString() + ", id=" + this.getId() + ", createTime=" + this.getCreateTime() + ", createdBy=" + this.getCreatedBy() + ")";
    }

    public interface Update extends Default {
    }

    public interface Save extends Default {
    }

}